<template>
    <v-table
            :pageSize="pageSize"
            :tableConfig="tableConfig"
            :tableData="tableData"
            :total="total"
            @findData="getTableData"
            @getTableData="getTableData"
            @searhData="setSearhData"
            @selectData="setSelectData"
            @setdialog="setdialog"
            @upData="getTableData"
            ref="table"
    ></v-table>
</template>

<script>
    import table from 'commons/Table'
    import baseMixin from "@/mixins/BaseMixin";

    export default {
        name: "Table",
        mixins: [baseMixin],
        props: {
            data: {
                type: Object
            }
        },
        data() {
            return {
                tableConfig: [
                    {
                        label: this.$t('bill.fieldName'),
                        prop: "field_name",
                        input: "input",
                    },
                    {
                        label: this.$t('bill.operatorName'),
                        prop: "operator",
                        input: "input",
                    },
                    {
                        label: this.$t('bill.firstValue'),
                        prop: "first_value",
                        input: "input",
                    },
                    {
                        label: this.$t('bill.secondValue'),
                        prop: "second_value",
                        input: "input",
                    },
                    {
                        label: this.$t('bill.filterConnector'),
                        prop: "filter_connector",
                        input: "input",
                    }
                ],
                tableData: [],
                pageSize: 10,
                total: 10,
                searhData: {}
            }
        },
        methods: {
            //获取table数据
            async getTableData(page, data) {
                try {
                    let res = await this.$api.post(`/queryActivityFilterList/${this.$store.state.wms}/${this.data.argument.activity_id}/${this.data.argument.facility_id}/${page}`, data);
                    
                        this.loading = false;
                        this.tableData = res.page.list;
                        this.pageSize = res.page.pageSize;
                        this.total = res.page.total;
                    
                } catch (e) {
                    this.$message.error(e);
                }
            },
            //搜索值
            setSearhData(data, up) {
                if (!up) {
                    this.searhData = data;
                } else {
                    this.searhData = data;
                    this.getTableData(1, this.searhData);
                }
            },
            //选中的数据
            setSelectData(data) {
                this.$parent.setSelectData(data)
            },
            //进入详情
            async setdialog(data) {
                this.$parent.setdialog(data, "activity_filter");
            },
        },
        mounted() {
            this.getTableData(1, {})
        },
        components: {
            'v-table': table
        }
    }
</script>

<style scoped>

</style>
